﻿using NUnit.Framework;
using Pyxis.FluentSelenium.Conditions;
using Pyxis.FluentSelenium.Locator;
using Selenium;

namespace Pyxis.FluentSelenium.SampleWebAppTest.SimpleExamples
{
    [TestFixture]
    public class AutoPostBackCheckboxTest
    {
        private WebApplication application;
        private User user;

        private static readonly PageLoadWaitCondition autoPostbackCheckboxPage = new PageLoadWaitCondition("SimpleExamples/autoPostBackDropDownListPage.aspx");
        private static readonly CheckBoxLocator blueCheckBox = CheckBoxLocator.WithId("chkBlue", autoPostbackCheckboxPage);
        private static readonly ElementLocator selectedColorLabel = ElementLocator.WithId("lblSelectedColor");

        [SetUp]
        public void Setup()
        {
            application = new WebApplication(3000, "Pyxis.FluentSelenium.SampleWebApp");
            application.Start();

            var selenium = new DefaultSelenium("127.0.0.1", 4445, "*iexplore", "http://localhost:3000/");
            user = new User(selenium);
            user.Start();
        }

        [TearDown]
        public void TearDown()
        {
            user.Stop();
            application.Stop();
        }

        [Test]
        public void TestCheckBlueCheckboxSetsTheLabelToTheSelectedColor()
        {
            user.Goto("SimpleExamples/AutoPostBackCheckbox.aspx");
            user.For(blueCheckBox).Clicks();

            user.For(selectedColorLabel).ShouldSee("Blue");
        }
    }
}
